﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Pibby.Core.IO;

namespace Pibby.Core.Tests.Stubs
{
	public class Drive : IDrive
	{
		public bool IsReady
		{
			get;
			set;
		}

		public string Name
		{
			get;
			set;
		}

		public string VolumeLabel
		{
			get;
			set;
		}

		public System.IO.DriveType DriveType
		{
			get;
			set;
		}

		public long AvailableFreeSpace
		{
			get;
			set;
		}

		public long TotalSize
		{
			get;
			set;
		}
	}

	public class DriveFactory : IDriveFactory
	{
		public IDriveCollection GetAllDrives()
		{
			const long megaByte = 1024 * 1024;
			const long gigaByte = megaByte * 1024;

			IDriveCollection collection = new IDriveCollection();

			// fake some drives...
			collection.Add(new Drive()
			{
				DriveType = System.IO.DriveType.Fixed,
				Name = "C:\\",
				VolumeLabel = "WINDOWS",
				AvailableFreeSpace = 100 * megaByte,
				IsReady = true,
				TotalSize = 100 * gigaByte
			});

			collection.Add(new Drive()
			{
				DriveType = System.IO.DriveType.CDRom,
				Name = "D:\\",
				VolumeLabel = "CD_ROM",
				AvailableFreeSpace = 0,
				IsReady = true,
				TotalSize = 600 * megaByte
			});

			collection.Add(new Drive()
			{
				DriveType = System.IO.DriveType.Removable,
				Name = "E:\\",
				VolumeLabel = "MEDIA_PLAYER",
				AvailableFreeSpace = 2 * megaByte,
				IsReady = true,
				TotalSize = 4 * gigaByte
			});

			return collection;
		}

		public IDrive GetDriveByName(string name)
		{
			var driveList = this.GetAllDrives();

			foreach (var drive in driveList)
			{
				if (drive.Name == name)
					return drive;
			}

			return null;
		}

		public IDrive GetDriveByLabel(string volumeLabel)
		{
			var driveList = this.GetAllDrives();

			foreach (var drive in driveList)
			{
				if (drive.VolumeLabel == volumeLabel)
					return drive;
			}

			return null;
		}

	}

}
